package com.twu.model;

import com.twu.biblioteca.OptionManager;

import java.util.Iterator;

/**
 * Created by Janu on 09/06/14.
 * Class: Librarian.java
 * Methods: public String checkInBook(Book b)
 *          public String checkOutBook(Book b)
 */

public class Librarian {

    //Librarian login
    public String login(String libPassword, OptionManager optionManager) {
        if(libPassword.equals("admin")){
            this.seeWhoCheckedOut(optionManager);
            return "Success";
        }
        else return "Failure";
    }

    //Display checked out books with customer number
    private boolean seeWhoCheckedOut(OptionManager optionManager) {
        int count=0;
        Iterator iter = optionManager.getBooks().iterator();

        Book aBooksList;
        System.out.println("Checked out Book");
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        System.out.format("%5s%75s%30s","Code","Book Name","Checked Out By");
        System.out.println("\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

        while(iter.hasNext()) {
            aBooksList = (Book) iter.next();
            if(!aBooksList.getBookCheckedOutBy().equals("")){
                System.out.format("%5s%75s%30s", aBooksList.getBookCode(), aBooksList.getBookName(), aBooksList.getBookCheckedOutBy());
                System.out.println();
                count++;
            }
        }

        return count>0;
    }
}
